package com.wy.authority.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wy.authority.entity.Configure;
import com.wy.authority.service.ConfigureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 忘忧
 * @Date Created in 2021/1/5 11:26
 * @Description:
 */
@RestController
@RequestMapping("mssg")
public class MessageController {
    @Autowired
    private ConfigureService configureService;


    @Autowired
    private RedisTemplate<String, String> redisTemplate;


    @GetMapping("/page")
    public Configure find_bynum(@RequestParam(defaultValue = "1") Integer pagenum, @RequestParam(defaultValue = "5") Integer pagesize) {

        return configureService.find_bynum(pagenum,pagesize);
    }

    //查询所有表
    @GetMapping("/find_all_table")
    public List<Configure> find_all_table(){
        List<Configure> list = configureService.find_all_table();
        return list;
    }

    //查询所有发送方式
    @GetMapping("/find_send")
    public List<Configure> find_send(){
        List<Configure> list = configureService.find_send();
        return list;
    }

    //查询配置
    @GetMapping("/findall")
    public List<Configure> findall(){
      List<Configure> list =configureService.findall();

      return list;
    }

    //查询指定表的所有字段
    @GetMapping("/find_column/{table_name}")
    public List<Configure> find_column(@PathVariable("table_name") String table_name){
        List<Configure> list = configureService.find_column(table_name);
        return list;
    }

    //查询用户
    @GetMapping("/finduser/{table_name}/{column_name}")
    public List<Configure> finduser(@PathVariable("table_name") String table_name,@PathVariable("column_name") String column_name){
        List<Configure> users = configureService.finduser(table_name,column_name);
        return users;
    }

    //模糊查询
    @ResponseBody
    @GetMapping("/select_query")
    public PageInfo<Configure> fuzzy_query(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer size,@RequestParam String msg_name, @RequestParam String send_way, @RequestParam String status, @RequestParam String istiming){
        PageHelper.startPage(page,size);
       List<Configure> list =configureService.fuzzy_query(msg_name,send_way,status,istiming);
        PageInfo<Configure> pageInfo =new PageInfo<>(list);
        return pageInfo;
    }
    //删除
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") Integer id){
        configureService.delete(id);
    }

    //插入
   @PostMapping("/insert")
    public String insert(@RequestBody Configure configure){
       System.out.println(configure);
       configureService.insert2(configure);
       configureService.insert(configure);
       configureService.insert3(configure);
       configureService.insert4(configure);
       return "success";
   }

   //通过查询
    @GetMapping("/findbyid/{id}")
    public List<Configure> find_byid(@PathVariable("id") Integer id){
        List<Configure> list= configureService.find_byid(id);
       return list;
    }

    //修改
    @PutMapping("/update")
    public String update(@RequestBody Configure configure){
         configureService.update(configure);
         configureService.update2(configure);
         configureService.update3(configure);
        return "success";
    }






}
